import { useMemo } from 'react';
import { Website } from '@/data/config';

interface UseWebsiteFilterProps {
  websites: Website[];
  searchQuery: string;
  activeCategory: string;
}

export const useWebsiteFilter = ({ 
  websites, 
  searchQuery, 
  activeCategory 
}: UseWebsiteFilterProps) => {
  
  const filteredWebsites = useMemo(() => {
    let filtered = websites;

    // 分类筛选
    if (activeCategory !== 'all') {
      filtered = filtered.filter(website => 
        website.category.includes(activeCategory)
      );
    }

    // 搜索筛选
    if (searchQuery.trim()) {
      const query = searchQuery.toLowerCase().trim();
      filtered = filtered.filter(website =>
        website.name.toLowerCase().includes(query) ||
        website.description.toLowerCase().includes(query) ||
        website.category.some(cat => cat.toLowerCase().includes(query))
      );
    }

    return filtered;
  }, [websites, searchQuery, activeCategory]);

  return {
    filteredWebsites,
    hasResults: filteredWebsites.length > 0,
    totalCount: websites.length,
    filteredCount: filteredWebsites.length,
  };
};